package com.cmbc.xiaodu.bill;

import com.baidu.dueros.bot.BaseBot;
import com.baidu.dueros.certificate.Certificate;
import com.baidu.dueros.data.request.IntentRequest;
import com.baidu.dueros.data.request.LaunchRequest;
import com.baidu.dueros.data.request.SessionEndedRequest;
import com.baidu.dueros.data.response.OutputSpeech;
import com.baidu.dueros.data.response.Reprompt;
import com.baidu.dueros.data.response.card.ListCard;
import com.baidu.dueros.data.response.card.StandardCardInfo;
import com.baidu.dueros.data.response.card.TextCard;
import com.baidu.dueros.model.Request;
import com.baidu.dueros.model.Response;
import com.fasterxml.jackson.databind.JsonMappingException;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class BillBot extends BaseBot {


    /**
     * 查询意图   带权限认证和跳转
     * 查询当月账单，要识别用户，成功后跳转进行查询
     */
    private Response askMyBill(){

        return null;
    }

    /**
     * 咨询意图  一个页面
     * 今日新闻，或者相似共同信息
     * @return
     */
    private Response askNews(){
        return null;
    }

    /**
     * 第一种情况推送意图 给我推送信用卡账单
     * 一个信用卡页面账单
     * [名] 	credit card
     * @return
     */
    private Response askMyCreditCard() {
        //制作一个模块，并使用会话记录重要数据
        TextCard textCard = new TextCard("您的信用卡号是多少?");
        textCard.setUrl("www:......");
        textCard.setAnchorText("信用卡账单");
        textCard.addCueWord("您的信用卡号?");
        setSessionAttribute("card_num", "value_1");
        setSessionAttribute("user_name", "value_2");
        OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "您的信用卡号是多少?");
        Reprompt reprompt = new Reprompt(outputSpeech);

        Response response = new Response();
        response.setCard(textCard);
        response.setOutputSpeech(outputSpeech);
        response.setReprompt(reprompt);
        return response;
    }


    /**
     * 重写onInent方法，处理onInent对话事件
     * 此处为针对同一意图的多个槽位进行回复。
     */
    @Override
    protected Response onInent(IntentRequest intentRequest) {

        // 判断NLU解析的意图名称是否匹配
        // 先判断意图，再确定槽位信息
        if ("billAction".equals(intentRequest.getIntentName())) {
            // 判断NLU解析解析后是否存在这个槽位
            if (getSlot("MyCreditCard") == null) {
                // 询问月薪槽位
                ask("MyCreditCard");
                return askMyCreditCard();
           /* } else if (getSlot("News") == null) {
                // 询问城市槽位
                ask("News");
                return askNews();
            } else if (getSlot("MyBill") == null) {
                // 询问查询种类槽位
                ask("MyBill");
                return askMyBill();*/
            } else {
                // 具体计算方法
//                compute();
            }
        }

        return null;
    }




    /**
     * 重写onSessionEnded事件，处理onSessionEnded对话事件
     *
     * @param sessionEndedRequest
     *            SessionEndedRequest请求体
     * @see com.baidu.dueros.bot.BaseBot#onSessionEnded(com.baidu.dueros.data.request.SessionEndedRequest)
     */
    @Override
    protected Response onSessionEnded(SessionEndedRequest sessionEndedRequest) {

        // 构造TextCard
        TextCard textCard = new TextCard("感谢使用民生服务");
        textCard.setAnchorText("setAnchorText");
        textCard.addCueWord("欢迎再次使用");

        // 构造OutputSpeech
        OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "欢迎再次使用服务");

        ListCard listCard = new ListCard();
        StandardCardInfo item1 = new StandardCardInfo("title1", "content1");
        StandardCardInfo item2 = new StandardCardInfo("title2", "content2");
        listCard.addStandardCardInfo(item1);
        listCard.addStandardCardInfo(item2);

        // 构造Response
        Response response = new Response(outputSpeech, textCard);

        return response;
    }

    /**
     * 重写onLaunch方法，处理onLaunch对话事件
     *
     * @param launchRequest
     *            LaunchRequest请求体
     * @see com.baidu.dueros.bot.BaseBot#onLaunch(com.baidu.dueros.data.request.LaunchRequest)
     */
    @Override
    protected Response onLaunch(LaunchRequest launchRequest) {
        // 新建文本卡片
        TextCard textCard = new TextCard("所得税为您服务");
        // 设置链接地址
        textCard.setUrl("www:....");
        // 设置链接内容
        textCard.setAnchorText("setAnchorText");
        // 添加引导话术
        textCard.addCueWord("欢迎进入");

        // 新建返回的语音内容
        OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "所得税为您服务");

        // 构造返回的Response
        Response response = new Response(outputSpeech, textCard);
        return response;
    }


    protected BillBot(Request request) throws IOException {
        super(request);
    }

    protected BillBot(String request) throws IOException, JsonMappingException {
        super(request);
    }

    protected BillBot(Certificate certificate) throws IOException {
        super(certificate);
    }

    protected BillBot(HttpServletRequest request) throws IOException, JsonMappingException {
        super(request);
    }

}
